package com.software.dao.impl;

import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.software.dao.UserDao;
import com.software.model.AdminUser;
import com.software.model.ModelCreate;

@Repository
public class UserDaoImpl implements UserDao {

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;

	@Override
	public AdminUser queryById(int id) {
		return (AdminUser) sqlSessionTemplate.selectOne("queryById", id);
	}

	@Override
	public int save(AdminUser u) {
		return sqlSessionTemplate.insert("insert-AdminUser", u);
	}

	@Override
	public int update(AdminUser u) {
		return sqlSessionTemplate.update("update-AdminUser", u);
	}

	@Override
	public int delete(Integer id) {
		return sqlSessionTemplate.delete("delete-AdminUser", id);
	}

	@Override
	public List<AdminUser> queryAll() {
		List<AdminUser> users =  sqlSessionTemplate.selectList("queryAll");
		return users;
	}
	
	@Override
	public List<ModelCreate> queryCol(String tableName){
		 return sqlSessionTemplate.selectList("sql-col", tableName);
	}

}
